package com.kang.consumer;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * RocketMQTemplate 集成了 DefaultLitePullConsumer
 * 源码请看 RocketMQAutoConfiguration
 */
//@Component
public class SpringPullConsumer implements InitializingBean {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        new Thread(() -> {
            while (true){
                List<String> receive = rocketMQTemplate.receive(String.class);
                for (String msg : receive) {
                    System.out.println("receive message: " + msg);
                }
            }
        }).start();
    }
}
